'-  teste1_0108231230_msx2+_screen12_conv.txt
'- 010808 - primeira tentativa no firstbasic-dos
'- input= 256x212 
'- output= 1x 53k s12 file

finp$="picture.jpg"

dim pr[4],pg[4],pb[4],dt[4],py[4]
f2$=finp$+".b12"
xed=256:yed=212
setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls
loadimage(finp$,1):pasteicon(0,0,1)
open f2$ for output as #2


for yp=0 to yed-1
  setcaption("line "+str$(yp)+"/211")
  for x=0 to 255 step 4

    for i=0 to 3
      c=point(x+i,yp)
      ri=bitwiseand((int(c/65536)),0xFF)
      gi=bitwiseand((int(c/256  )),0xFF)
      bi=bitwiseand(c,0xFF)
      pb[i]=bi:pg[i]=gi:pr[i]=ri
      next

    r=0:g=0:b=0
    for i=0 to 3
      r=r+pr[i]:g=g+pg[i]:b=b+pb[i]:next
    r=int(r/4):g=int(g/4):b=int(b/4) 

    y=int((b/2)+(r/4)+(g/8))
    'j=r-y
    'k=g-y

    j=int((r-y)/2)
    k=int((g-y)/2)
    
    if y<0 then:y=0:end if
    if y>255 then:y=255:end if
    if j<-128 then:j=-128:end if
    if j>127 then:j=127:end if
    if k<-128 then:k=-128:end if
    if k>127 then:k=127:end if
    j=(256+j)mod 256
    k=(256+k)mod 256

    kl=(bitwiseand(k,28)/4)
    kh=(bitwiseand(k,224)/32)
    jl=(bitwiseand(j,28)/4)
    jh=(bitwiseand(j,224)/32)

    for i=0 to 3
      py[i]=int(pb[i]/2)+(pr[i]/4)+(pg[i]/8) 
      next

    dt[0]=bitwiseor( bitwiseand(py[0],248),kl)
    dt[1]=bitwiseor( bitwiseand(py[1],248),kh)
    dt[2]=bitwiseor( bitwiseand(py[2],248),jl)
    dt[3]=bitwiseor( bitwiseand(py[3],248),jh)

    for i=0 to 3
      writebyte(2,dt[i])
      next:next:next

close #2


setcaption("done")
'waitkey

'------------------------------------------------------

'- picture size proportion
'- 256x212 from 270x288
'- 364x212 from 384x288   (364x212 = 172/100 proportion)


'------------------------------------------------------
'100 SCREEN0:WIDTH40:SCREEN12:COLOR 1,15,0:CLS
'102 A$="DSC00878"
'108 BLOAD A$+".S12",S
'112 IF INKEY$<>CHR$(27) THEN GOTO 112
'114 VDP(10)=VDP(10) AND 243:STOP
'116 SAVE"AUTOEXEC.BAS",A

'-------------------------------------------------------
'100 SCREEN0:WIDTH40:SCREEN12,,,,,0:COLOR 1,15,0:CLS
'102 A$="DSC00878":VDP(10)=VDP(10) OR 12
'106 FOR I=0 TO 1:SET PAGE I,I:CLS:NEXT
'108 SET PAGE ,0:BLOAD A$+".SX0",S
'110 SET PAGE ,1:BLOAD A$+".SX1",S
'112 IF INKEY$<>CHR$(27) THEN GOTO 112
'114 VDP(10)=VDP(10) AND 243:STOP
'116 SAVE"AUTOEXEC.BAS",A

